package com.liuxinlong.common.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * redis缓存配置
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2022年5月17日
 */
@Configuration
public class RedisConfiguration {
    @Autowired
    private RedisConnectionFactory redisConnectionFactory;

    @Bean
    public RedisMessageListenerContainer container(){
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(redisConnectionFactory);
        // 可以添加多个messageListener，配置不同的交换机
        container.addMessageListener(listener(),new PatternTopic("channel:push"));
        return container;
    }

    @Bean
    public PushSubscribeListener listener(){
        return new PushSubscribeListener();
    }


}
